# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Marco44 (Marc Cousin) <cousinmarc at gmail dot com>

pkgname=pgformatter
pkgver=5.5
pkgrel=1
pkgdesc='A PostgreSQL SQL syntax beautifier'
arch=('any')
url='https://github.com/darold/pgformatter'
license=('BSD')
depends=('perl')
makedepends=('git')
_commit='bacb8bb61df81846ae9d6b624a4c87454dc96bec'
source=("$pkgname::git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

build() {
  cd "$pkgname"

  unset PERL5LIB PERL_MM_OPT PERL_LOCAL_LIB_ROOT
  export PERL_MM_USE_DEFAULT=1 PERL_AUTOINSTALL=--skipdeps

  perl Makefile.PL
  make
}

check() {
  cd "$pkgname"

  unset PERL5LIB PERL_MM_OPT PERL_LOCAL_LIB_ROOT
  export PERL_MM_USE_DEFAULT=1

  make test
}

package() {
  cd "$pkgname"

  unset PERL5LIB PERL_MM_OPT PERL_LOCAL_LIB_ROOT
  make install INSTALLDIRS=vendor DESTDIR="$pkgdir"

  # provide symlink in /usr/bin for non-interactive shells
  ln -sf /usr/bin/vendor_perl/pg_format "$pkgdir/usr/bin/pg_format"

  # delete usr/lib as it's empty ...
  rm -rf "$pkgdir/usr/lib"

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
